package Orders;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class OrderGroupingComparator extends WritableComparator {
    public OrderGroupingComparator() {
        super(OrderBean.class,true);//是否实例化

    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        int result;
        OrderBean aBean = (OrderBean) a;//子父类关系（OrderBean实现了WritableComparable接口）
        OrderBean bBean = (OrderBean) b;
        //分组比较(相等的Order_id放在一起)
        if(aBean.getOrder_id()>bBean.getOrder_id()) {
              result = 1;

          }else if(aBean.getOrder_id()<bBean.getOrder_id()){
            result = -1;

          }else{
            result = 0;//属于一组
        }
        return  result;
    }
}
